/*
Navicat MySQL Data Transfer

Source Server         : localhost_3306
Source Server Version : 50616
Source Host           : localhost:3306
Source Database       : luxdiner

Target Server Type    : MYSQL
Target Server Version : 50616
File Encoding         : 65001

Date: 2014-03-14 16:12:55
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `banks`
-- ----------------------------
DROP TABLE IF EXISTS `banks`;
CREATE TABLE `banks` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `BankName` varchar(100) NOT NULL,
  `CardNo` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of banks
-- ----------------------------
INSERT INTO `banks` VALUES ('1', '现金', null);
INSERT INTO `banks` VALUES ('2', '交行', '4321442155896891007');

-- ----------------------------
-- Table structure for `buy_records`
-- ----------------------------
DROP TABLE IF EXISTS `buy_records`;
CREATE TABLE `buy_records` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `OrderNo` varchar(20) NOT NULL,
  `ProductID` int(11) NOT NULL,
  `SupplierID` int(11) NOT NULL,
  `UnitID` int(11) NOT NULL,
  `Quantity` int(11) NOT NULL,
  `UnitPrice` decimal(10,5) NOT NULL,
  `BuyTime` datetime NOT NULL,
  `CreatedOn` datetime NOT NULL,
  `OperatorUserID` int(11) NOT NULL,
  `HouseID` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID`),
  KEY `FK_Buy_Records_Products` (`ProductID`),
  KEY `FK_Buy_Records_Suppliers` (`SupplierID`),
  KEY `FK_Buy_Records_Product_Units` (`UnitID`),
  KEY `FK_Buy_Records_Users` (`OperatorUserID`),
  KEY `FK_Buy_Records_Warehouse` (`HouseID`),
  CONSTRAINT `FK_Buy_Records_Products` FOREIGN KEY (`ProductID`) REFERENCES `products` (`ID`),
  CONSTRAINT `FK_Buy_Records_Product_Units` FOREIGN KEY (`UnitID`) REFERENCES `product_units` (`ID`),
  CONSTRAINT `FK_Buy_Records_Suppliers` FOREIGN KEY (`SupplierID`) REFERENCES `suppliers` (`ID`),
  CONSTRAINT `FK_Buy_Records_Users` FOREIGN KEY (`OperatorUserID`) REFERENCES `users` (`ID`),
  CONSTRAINT `FK_Buy_Records_Warehouse` FOREIGN KEY (`HouseID`) REFERENCES `warehouses` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of buy_records
-- ----------------------------
INSERT INTO `buy_records` VALUES ('21', '20AB507FD6', '3', '2', '6', '80', '20.00000', '2014-03-13 00:00:00', '2014-03-13 13:31:30', '2', '1');
INSERT INTO `buy_records` VALUES ('22', '20AB508A14', '1', '1', '4', '468', '5.00000', '2014-03-13 00:00:00', '2014-03-13 13:57:03', '2', '1');
INSERT INTO `buy_records` VALUES ('23', '20AB50A81F', '2', '2', '7', '500', '18.00000', '2014-03-13 00:00:00', '2014-03-13 14:33:47', '2', '2');
INSERT INTO `buy_records` VALUES ('24', '20AB50EA88', '1', '2', '4', '47', '15.00000', '2014-03-13 00:00:00', '2014-03-13 16:03:49', '2', '2');
INSERT INTO `buy_records` VALUES ('25', '20AB511509', '2', '2', '7', '20', '18.00000', '2014-03-13 00:00:00', '2014-03-13 17:12:38', '2', '1');
INSERT INTO `buy_records` VALUES ('26', '20AB511509', '3', '2', '6', '50', '20.00000', '2014-03-13 00:00:00', '2014-03-13 17:12:38', '2', '1');
INSERT INTO `buy_records` VALUES ('27', '20AB5FC658', '2', '2', '7', '13', '18.00000', '2014-03-14 00:00:00', '2014-03-14 13:41:20', '2', '1');
INSERT INTO `buy_records` VALUES ('28', 'R-20AB5FC7B0', '2', '1', '7', '12', '5.00000', '2014-03-14 00:00:00', '2014-03-14 13:45:12', '2', '1');
INSERT INTO `buy_records` VALUES ('29', 'R-20AB5FC7B0', '1', '1', '4', '13', '5.00000', '2014-03-14 00:00:00', '2014-03-14 13:45:12', '2', '1');

-- ----------------------------
-- Table structure for `customers`
-- ----------------------------
DROP TABLE IF EXISTS `customers`;
CREATE TABLE `customers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Corporation` varchar(100) DEFAULT NULL,
  `RealName` varchar(30) NOT NULL,
  `Address` varchar(300) NOT NULL,
  `Mobile` varchar(20) NOT NULL,
  `CType` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of customers
-- ----------------------------
INSERT INTO `customers` VALUES ('2', '王五', '王五', '百里西路75号', '13644557788', '1');
INSERT INTO `customers` VALUES ('3', '百家乐KTV', '张三', '', '13855997799', '1');

-- ----------------------------
-- Table structure for `customer_categories`
-- ----------------------------
DROP TABLE IF EXISTS `customer_categories`;
CREATE TABLE `customer_categories` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `CategoryName` varchar(50) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of customer_categories
-- ----------------------------
INSERT INTO `customer_categories` VALUES ('1', 'VIP');
INSERT INTO `customer_categories` VALUES ('2', '会所');

-- ----------------------------
-- Table structure for `customer_in_category`
-- ----------------------------
DROP TABLE IF EXISTS `customer_in_category`;
CREATE TABLE `customer_in_category` (
  ` CustomerID` int(11) NOT NULL,
  `CategoryID` int(11) NOT NULL,
  PRIMARY KEY (` CustomerID`,`CategoryID`),
  KEY `FK_Customer_In_Categories_Categories` (`CategoryID`),
  CONSTRAINT `FK_Customer_In_Categories_Categories` FOREIGN KEY (`CategoryID`) REFERENCES `customer_categories` (`ID`),
  CONSTRAINT `FK_Customer_In_Categories_Customers` FOREIGN KEY (` CustomerID`) REFERENCES `customers` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of customer_in_category
-- ----------------------------
INSERT INTO `customer_in_category` VALUES ('2', '1');
INSERT INTO `customer_in_category` VALUES ('3', '2');

-- ----------------------------
-- Table structure for `incomes`
-- ----------------------------
DROP TABLE IF EXISTS `incomes`;
CREATE TABLE `incomes` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `CustomerID` int(11) NOT NULL,
  `Quantity` decimal(10,5) NOT NULL,
  `Description` varchar(500) NOT NULL,
  `Balance` decimal(10,5) NOT NULL,
  `NoteTime` datetime NOT NULL,
  `CreatedOn` datetime NOT NULL,
  `OperatorUserID` int(11) NOT NULL,
  `OrderNo` varchar(50) DEFAULT NULL,
  `BankID` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `FK_Incomes_Customers` (`CustomerID`),
  KEY `FK_Incomes_Users` (`OperatorUserID`),
  KEY `FK_Incomes_Banks` (`BankID`),
  CONSTRAINT `FK_Incomes_Banks` FOREIGN KEY (`BankID`) REFERENCES `banks` (`ID`),
  CONSTRAINT `FK_Incomes_Customers` FOREIGN KEY (`CustomerID`) REFERENCES `customers` (`ID`),
  CONSTRAINT `FK_Incomes_Users` FOREIGN KEY (`OperatorUserID`) REFERENCES `users` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of incomes
-- ----------------------------
INSERT INTO `incomes` VALUES ('8', '3', '190.40000', '出库单', '190.40000', '2014-03-13 00:00:00', '2014-03-13 13:57:44', '2', '20AB508A60', null);
INSERT INTO `incomes` VALUES ('9', '2', '1299.00000', '出库单', '1299.00000', '2014-03-14 00:00:00', '2014-03-14 13:48:41', '2', 'C-20AB5FC918', null);

-- ----------------------------
-- Table structure for `order_products`
-- ----------------------------
DROP TABLE IF EXISTS `order_products`;
CREATE TABLE `order_products` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `OrderNo` varchar(255) NOT NULL,
  `CustomerID` int(11) NOT NULL,
  `NoteDate` datetime NOT NULL,
  `HouseID` int(11) NOT NULL,
  `OperatorUserID` int(11) NOT NULL,
  `CreatedOn` datetime NOT NULL,
  `TotalMoney` decimal(10,2) NOT NULL,
  `OType` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of order_products
-- ----------------------------

-- ----------------------------
-- Table structure for `order_product_details`
-- ----------------------------
DROP TABLE IF EXISTS `order_product_details`;
CREATE TABLE `order_product_details` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `OID` int(11) NOT NULL,
  `Product` int(11) NOT NULL,
  `Quantity` int(11) NOT NULL,
  `UnitPrice` decimal(10,2) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of order_product_details
-- ----------------------------

-- ----------------------------
-- Table structure for `outlays`
-- ----------------------------
DROP TABLE IF EXISTS `outlays`;
CREATE TABLE `outlays` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `SupplierID` int(11) NOT NULL,
  `Quantity` decimal(10,5) NOT NULL,
  `Description` varchar(500) NOT NULL,
  `Balance` decimal(10,5) NOT NULL,
  `NoteTime` datetime NOT NULL,
  `CreatedOn` datetime NOT NULL,
  `OperatorUserID` int(11) NOT NULL,
  `OrderNo` varchar(20) NOT NULL,
  `BankID` int(11) DEFAULT NULL,
  `Method` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID`),
  KEY `FK_Expenses_Suppliers` (`SupplierID`),
  KEY `FK_Expenses_Users` (`OperatorUserID`),
  KEY `FK_Outlays_Banks` (`BankID`),
  CONSTRAINT `FK_Outlays_Banks` FOREIGN KEY (`BankID`) REFERENCES `banks` (`ID`),
  CONSTRAINT `FK_Outlays_Suppliers` FOREIGN KEY (`SupplierID`) REFERENCES `suppliers` (`ID`),
  CONSTRAINT `FK_Outlays_Users` FOREIGN KEY (`OperatorUserID`) REFERENCES `users` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of outlays
-- ----------------------------
INSERT INTO `outlays` VALUES ('8', '2', '1600.00000', '入库单', '1600.00000', '2014-03-13 00:00:00', '2014-03-13 13:31:30', '2', '20AB507FD6', null, '1');
INSERT INTO `outlays` VALUES ('9', '1', '2340.00000', '入库单', '2340.00000', '2014-03-13 00:00:00', '2014-03-13 13:57:03', '2', '20AB508A14', null, '1');
INSERT INTO `outlays` VALUES ('10', '2', '9000.00000', '入库单', '10600.00000', '2014-03-13 00:00:00', '2014-03-13 14:33:47', '2', '20AB50A81F', null, '1');
INSERT INTO `outlays` VALUES ('11', '2', '705.00000', '入库单', '11305.00000', '2014-03-13 00:00:00', '2014-03-13 16:03:49', '2', '20AB50EA88', null, '1');
INSERT INTO `outlays` VALUES ('12', '2', '1360.00000', '入库单', '12665.00000', '2014-03-13 00:00:00', '2014-03-13 17:12:38', '2', '20AB511509', null, '1');
INSERT INTO `outlays` VALUES ('13', '2', '234.00000', '入库单', '12899.00000', '2014-03-14 00:00:00', '2014-03-14 13:41:20', '2', '20AB5FC658', null, '1');
INSERT INTO `outlays` VALUES ('14', '1', '125.00000', '入库单', '2465.00000', '2014-03-14 00:00:00', '2014-03-14 13:45:13', '2', 'R-20AB5FC7B0', null, '1');

-- ----------------------------
-- Table structure for `outlay_details`
-- ----------------------------
DROP TABLE IF EXISTS `outlay_details`;
CREATE TABLE `outlay_details` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `OID` int(11) NOT NULL,
  `BankID` int(11) NOT NULL,
  `Money` decimal(10,2) NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `FK_OutLay_Details_OutLays` (`OID`),
  KEY `FK_OutLay_Details_Banks` (`BankID`),
  CONSTRAINT `FK_OutLay_Details_Banks` FOREIGN KEY (`BankID`) REFERENCES `banks` (`ID`),
  CONSTRAINT `FK_OutLay_Details_OutLays` FOREIGN KEY (`OID`) REFERENCES `outlays` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of outlay_details
-- ----------------------------

-- ----------------------------
-- Table structure for `products`
-- ----------------------------
DROP TABLE IF EXISTS `products`;
CREATE TABLE `products` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `ProductNo` varchar(20) NOT NULL,
  `ProductName` varchar(100) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='产品目录';

-- ----------------------------
-- Records of products
-- ----------------------------
INSERT INTO `products` VALUES ('1', 'PJ-001', '5L-哈亨黑啤');
INSERT INTO `products` VALUES ('2', 'X-001', '阿根廷红虾1#');
INSERT INTO `products` VALUES ('3', 'X-003', '西班牙粉红大虾（1#）');

-- ----------------------------
-- Table structure for `product_categories`
-- ----------------------------
DROP TABLE IF EXISTS `product_categories`;
CREATE TABLE `product_categories` (
  `ID` int(4) NOT NULL AUTO_INCREMENT,
  `PID` int(4) DEFAULT NULL,
  `CategoryName` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `FK_Product_Categories_Product_Categories` (`PID`),
  CONSTRAINT `FK_Product_Categories_Product_Categories` FOREIGN KEY (`PID`) REFERENCES `product_categories` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of product_categories
-- ----------------------------
INSERT INTO `product_categories` VALUES ('1', null, '啤酒');
INSERT INTO `product_categories` VALUES ('2', null, '海鲜');
INSERT INTO `product_categories` VALUES ('3', null, '肉类');

-- ----------------------------
-- Table structure for `product_in_category`
-- ----------------------------
DROP TABLE IF EXISTS `product_in_category`;
CREATE TABLE `product_in_category` (
  `ProductID` int(11) NOT NULL,
  `CategoryID` int(11) NOT NULL,
  PRIMARY KEY (`ProductID`,`CategoryID`),
  KEY `Fk_Product_In_Category_Categories` (`CategoryID`),
  CONSTRAINT `Fk_Product_In_Category_Categories` FOREIGN KEY (`CategoryID`) REFERENCES `product_categories` (`ID`) ON DELETE CASCADE,
  CONSTRAINT `Fk_Product_In_Category_Products` FOREIGN KEY (`ProductID`) REFERENCES `products` (`ID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of product_in_category
-- ----------------------------
INSERT INTO `product_in_category` VALUES ('1', '1');
INSERT INTO `product_in_category` VALUES ('2', '2');
INSERT INTO `product_in_category` VALUES ('3', '2');
INSERT INTO `product_in_category` VALUES ('1', '3');

-- ----------------------------
-- Table structure for `product_units`
-- ----------------------------
DROP TABLE IF EXISTS `product_units`;
CREATE TABLE `product_units` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `ProductID` int(11) NOT NULL,
  `UnitName` varchar(20) NOT NULL,
  `Rate` int(11) NOT NULL,
  `CostPrice` decimal(10,5) NOT NULL,
  `SellPrice` decimal(10,5) NOT NULL,
  `OrderIndex` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`),
  KEY `FK_Product_Unit_Products` (`ProductID`),
  CONSTRAINT `FK_Product_Unit_Products` FOREIGN KEY (`ProductID`) REFERENCES `products` (`ID`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of product_units
-- ----------------------------
INSERT INTO `product_units` VALUES ('4', '1', '瓶', '1', '5.00000', '6.00000', '1');
INSERT INTO `product_units` VALUES ('5', '1', '箱', '6', '25.00000', '30.00000', '2');
INSERT INTO `product_units` VALUES ('6', '3', '只', '1', '15.00000', '20.00000', '0');
INSERT INTO `product_units` VALUES ('7', '2', '只', '1', '0.00000', '0.00000', '0');
INSERT INTO `product_units` VALUES ('9', '2', '包', '15', '0.00000', '0.00000', '0');

-- ----------------------------
-- Table structure for `repertories`
-- ----------------------------
DROP TABLE IF EXISTS `repertories`;
CREATE TABLE `repertories` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `OrderNo` varchar(20) DEFAULT NULL,
  `ProductID` int(11) NOT NULL,
  `UnitID` int(11) NOT NULL,
  `Quantity` int(11) NOT NULL,
  `Balance` int(11) NOT NULL,
  `Description` varchar(100) DEFAULT NULL,
  `CreatedOn` datetime NOT NULL,
  `Method` int(11) NOT NULL DEFAULT '1',
  `HouseID` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID`),
  KEY `FK_Repertories_Product` (`ProductID`),
  KEY `FK_Repertories_Unit` (`UnitID`),
  KEY `FK_Repertories_Warehouse` (`HouseID`),
  CONSTRAINT `FK_Repertories_Product` FOREIGN KEY (`ProductID`) REFERENCES `products` (`ID`),
  CONSTRAINT `FK_Repertories_Unit` FOREIGN KEY (`UnitID`) REFERENCES `product_units` (`ID`),
  CONSTRAINT `FK_Repertories_Warehouse` FOREIGN KEY (`HouseID`) REFERENCES `warehouses` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of repertories
-- ----------------------------
INSERT INTO `repertories` VALUES ('32', '20AB507FD6', '3', '6', '80', '80', '入库', '2014-03-13 00:00:00', '1', '1');
INSERT INTO `repertories` VALUES ('33', '20AB508A14', '1', '4', '468', '468', '入库', '2014-03-13 00:00:00', '1', '1');
INSERT INTO `repertories` VALUES ('34', '20AB508A60', '1', '4', '-28', '440', '出库', '2014-03-13 00:00:00', '2', '1');
INSERT INTO `repertories` VALUES ('35', '20AB50A81F', '2', '7', '500', '500', '入库', '2014-03-13 00:00:00', '1', '2');
INSERT INTO `repertories` VALUES ('36', '20AB50EA88', '1', '4', '47', '47', '入库', '2014-03-13 00:00:00', '1', '2');
INSERT INTO `repertories` VALUES ('37', null, '1', '4', '50', '490', '盘存', '2014-03-13 16:08:19', '3', '1');
INSERT INTO `repertories` VALUES ('38', null, '1', '4', '-50', '440', '仓库调拨--拨出', '2014-03-13 16:45:25', '4', '1');
INSERT INTO `repertories` VALUES ('39', null, '1', '4', '50', '97', '仓库调拨--拨入', '2014-03-13 16:45:25', '4', '2');
INSERT INTO `repertories` VALUES ('40', '20AB511509', '2', '7', '20', '20', '入库', '2014-03-13 00:00:00', '1', '1');
INSERT INTO `repertories` VALUES ('41', '20AB511509', '3', '6', '50', '130', '入库', '2014-03-13 00:00:00', '1', '1');
INSERT INTO `repertories` VALUES ('42', '20AB5FC658', '2', '7', '13', '33', '入库', '2014-03-14 00:00:00', '1', '1');
INSERT INTO `repertories` VALUES ('43', 'R-20AB5FC7B0', '2', '7', '12', '45', '入库', '2014-03-14 00:00:00', '1', '1');
INSERT INTO `repertories` VALUES ('44', 'R-20AB5FC7B0', '1', '4', '13', '453', '入库', '2014-03-14 00:00:00', '1', '1');
INSERT INTO `repertories` VALUES ('45', 'C-20AB5FC918', '2', '7', '-21', '24', '出库', '2014-03-14 00:00:00', '2', '1');
INSERT INTO `repertories` VALUES ('46', 'C-20AB5FC918', '1', '4', '-36', '417', '出库', '2014-03-14 00:00:00', '2', '1');

-- ----------------------------
-- Table structure for `roles`
-- ----------------------------
DROP TABLE IF EXISTS `roles`;
CREATE TABLE `roles` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `RoleName` varchar(45) NOT NULL,
  `Description` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of roles
-- ----------------------------
INSERT INTO `roles` VALUES ('1', 'Admin', '系统管理员');
INSERT INTO `roles` VALUES ('2', 'Sales', '销售员');
INSERT INTO `roles` VALUES ('3', 'Financial', '财务人员');
INSERT INTO `roles` VALUES ('4', 'Stockman', '仓库管理员');

-- ----------------------------
-- Table structure for `sell_records`
-- ----------------------------
DROP TABLE IF EXISTS `sell_records`;
CREATE TABLE `sell_records` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `OrderNo` varchar(20) NOT NULL,
  `ProductID` int(11) NOT NULL,
  `CustomerID` int(11) NOT NULL,
  `UnitID` int(11) NOT NULL,
  `UnitPrice` decimal(10,5) NOT NULL,
  `Quantity` int(11) NOT NULL,
  `SellTime` datetime NOT NULL,
  `CreatedOn` datetime NOT NULL,
  `OperatorUserID` int(11) NOT NULL,
  `HouseID` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID`),
  KEY `FK_Sell_Records_Products` (`ProductID`),
  KEY `FK_Sell_Records_Customers` (`CustomerID`),
  KEY `FK_Sell_Records_Product_Units` (`UnitID`),
  KEY `FK_Sell_Records_Users` (`OperatorUserID`),
  KEY `FK_Sell_Records_Warehouses` (`HouseID`),
  CONSTRAINT `FK_Sell_Records_Customers` FOREIGN KEY (`CustomerID`) REFERENCES `customers` (`ID`),
  CONSTRAINT `FK_Sell_Records_Products` FOREIGN KEY (`ProductID`) REFERENCES `products` (`ID`),
  CONSTRAINT `FK_Sell_Records_Product_Units` FOREIGN KEY (`UnitID`) REFERENCES `product_units` (`ID`),
  CONSTRAINT `FK_Sell_Records_Users` FOREIGN KEY (`OperatorUserID`) REFERENCES `users` (`ID`),
  CONSTRAINT `FK_Sell_Records_Warehouses` FOREIGN KEY (`HouseID`) REFERENCES `warehouses` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of sell_records
-- ----------------------------
INSERT INTO `sell_records` VALUES ('11', '20AB508A60', '1', '3', '4', '6.80000', '28', '2014-03-13 00:00:00', '2014-03-13 13:57:44', '2', '1');
INSERT INTO `sell_records` VALUES ('12', 'C-20AB5FC918', '2', '2', '7', '7.00000', '21', '2014-03-14 00:00:00', '2014-03-14 13:48:41', '2', '1');
INSERT INTO `sell_records` VALUES ('13', 'C-20AB5FC918', '1', '2', '4', '32.00000', '36', '2014-03-14 00:00:00', '2014-03-14 13:48:41', '2', '1');

-- ----------------------------
-- Table structure for `suppliers`
-- ----------------------------
DROP TABLE IF EXISTS `suppliers`;
CREATE TABLE `suppliers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Corporation` varchar(100) DEFAULT NULL,
  `RealName` varchar(50) DEFAULT NULL,
  `Address` varchar(300) NOT NULL,
  `Mobile` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of suppliers
-- ----------------------------
INSERT INTO `suppliers` VALUES ('1', '法国Blue Catch', 'Elics T', 'Road 5 Tian', '13858855885');
INSERT INTO `suppliers` VALUES ('2', '上海进出口贸易有限公司', '朱成', '上海市徐家汇天贸广场1905', '13055996898');

-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Guid` varchar(36) NOT NULL,
  `UserName` varchar(45) NOT NULL,
  `Password` varchar(45) NOT NULL,
  `RealName` varchar(45) NOT NULL,
  `Mobile` varchar(45) DEFAULT NULL,
  `Status` int(11) DEFAULT '0',
  `LastLoginTime` datetime DEFAULT NULL,
  `LoginTryTimes` int(11) NOT NULL DEFAULT '0',
  `CreatedOn` datetime NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID_UNIQUE` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='用户表';

-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES ('2', '1a1a4bff-fd27-4820-8bce-0ba66a075bfb', 'admin', 'afdd0b4ad2ec172c586e2150770fbf9e', '朱成', '13968888810', '1', '2014-03-13 09:53:58', '0', '2014-03-06 10:36:16');

-- ----------------------------
-- Table structure for `user_in_role`
-- ----------------------------
DROP TABLE IF EXISTS `user_in_role`;
CREATE TABLE `user_in_role` (
  `UserID` int(11) NOT NULL,
  `RoleID` int(11) NOT NULL,
  PRIMARY KEY (`UserID`,`RoleID`),
  KEY `FK_UserInRole_Roles_idx` (`RoleID`),
  CONSTRAINT `FK_UserInRole_Roles` FOREIGN KEY (`RoleID`) REFERENCES `roles` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
  CONSTRAINT `FK_UserInRole_Users` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user_in_role
-- ----------------------------
INSERT INTO `user_in_role` VALUES ('2', '1');

-- ----------------------------
-- Table structure for `warehouses`
-- ----------------------------
DROP TABLE IF EXISTS `warehouses`;
CREATE TABLE `warehouses` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `House` varchar(50) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of warehouses
-- ----------------------------
INSERT INTO `warehouses` VALUES ('1', '一号仓');
INSERT INTO `warehouses` VALUES ('2', '备用仓');

-- ----------------------------
-- View structure for `view_buy_record_group`
-- ----------------------------
DROP VIEW IF EXISTS `view_buy_record_group`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_buy_record_group` AS select `buy_records`.`OrderNo` AS `OrderNo`,`buy_records`.`SupplierID` AS `SupplierID`,`buy_records`.`BuyTime` AS `BuyTime`,`buy_records`.`OperatorUserID` AS `OperatorUserID`,sum((`buy_records`.`UnitPrice` * `buy_records`.`Quantity`)) AS `Sum`,`buy_records`.`HouseID` AS `HouseID` from `buy_records` group by `buy_records`.`OrderNo`,`buy_records`.`SupplierID`,`buy_records`.`BuyTime`,`buy_records`.`OperatorUserID`,`buy_records`.`HouseID` ;

-- ----------------------------
-- View structure for `view_repertory_group`
-- ----------------------------
DROP VIEW IF EXISTS `view_repertory_group`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_repertory_group` AS select max(`repertories`.`ID`) AS `ID` from `repertories` group by `repertories`.`ProductID`,`repertories`.`HouseID` ;

-- ----------------------------
-- View structure for `view_repertory_tops`
-- ----------------------------
DROP VIEW IF EXISTS `view_repertory_tops`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_repertory_tops` AS select `a`.`ID` AS `ID`,`a`.`OrderNo` AS `OrderNo`,`a`.`ProductID` AS `ProductID`,`a`.`UnitID` AS `UnitID`,`a`.`Quantity` AS `Quantity`,`a`.`Balance` AS `Balance`,`a`.`Description` AS `Description`,`a`.`CreatedOn` AS `CreatedOn`,`a`.`Method` AS `Method`,`a`.`HouseID` AS `HouseID` from (`repertories` `a` join `view_repertory_group` `b` on((`a`.`ID` = `b`.`ID`))) ;

-- ----------------------------
-- View structure for `view_sell_record_group`
-- ----------------------------
DROP VIEW IF EXISTS `view_sell_record_group`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_sell_record_group` AS select `sell_records`.`OrderNo` AS `OrderNo`,`sell_records`.`CustomerID` AS `CustomerID`,`sell_records`.`SellTime` AS `SellTime`,`sell_records`.`OperatorUserID` AS `OperatorUserID`,sum((`sell_records`.`UnitPrice` * `sell_records`.`Quantity`)) AS `Sum`,`sell_records`.`HouseID` AS `HouseID` from `sell_records` group by `sell_records`.`OrderNo`,`sell_records`.`CustomerID`,`sell_records`.`SellTime`,`sell_records`.`OperatorUserID`,`sell_records`.`HouseID` ;
